home *** CD-ROM | disk | FTP | other *** search
- /*//////////////////////////////////////////////////////////////////////
- Filename: fwn-sdbfncs.js
- Company Name: Computer Associates International, Inc.
- Legal Copyright: Copyright (c) Computer Associates International, Inc.
- Author: Ales Novak
- Product: Tiny Firewall
- Description: javascript code to access active FW db through XMLSecDBParser COM iface
- ///////////////////////////////////////////////////////////////////////*/
-
- // requires sdb-consts.js + sdb-msgs.js + tools.js
-
- ///////////////////////////////////////////////////////////////////////
- // getRuleList - internal function
- function FW_getRuleList( bUseClientParser, bIsRoutedRule )
- {
- if ( parseBoolean(bIsRoutedRule) == 0 )
- {
- if ( parseBoolean( bUseClientParser ) == 0)
- return external.ServerParser(XM_FW).RuleList;
- else
- return external.ClientParser(XM_FW).RuleList;
- }
- else
- return external.ServerParser(XM_FW).RoutedRuleList;
- }
-
- ///////////////////////////////////////////////////////////////////////
- // getDefinitionList - internal function
- function getDefinitionList( bUseClientParser )
- {
- return (parseBoolean(bUseClientParser) != 0) ? external.ClientParser(XM_FW).DefinitionList : external.ServerParser(XM_FW).DefinitionList;
- }
-
- function SaveParser( bUseClientParser)
- {
- var parser;
- if ( parseBoolean( bUseClientParser ) == 0)
- parser = external.ServerParser(XM_FW);
- else
- parser = external.ClientParser(XM_FW);
-
- parser.Save(parser.FilePath);
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_AddRuleByTransportID
- function FW_AddRuleByTransportID( strTransportID, strRemIpAddrID, strRemIpAddr, eZoneMask,
- strAppGroupID, strAppLabel, iAccount, iAccessResult, iAuditLevel, strRuleDescription, bHighPriority, bUseClientParser,
- strUsers, strDayTimeID, strDayTime )
- {
- return FW_AddRuleImpl( strTransportID, 0, 0, 0, 0, "", "", strRemIpAddrID, strRemIpAddr, "", "", eZoneMask,
- strAppGroupID, strAppLabel, iAccount, iAccessResult, iAuditLevel, strRuleDescription, bHighPriority, false, false, bUseClientParser,
- strUsers, strDayTimeID, strDayTime );
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_AddRuleImpl
- // either strTransportID can be used or combination of eProtocol, iCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts
- // Transport definition => for PROT_ICMP, set eDirection and eICMPType only
- // Transport definition => for PROT_IP => nothing to set
- // Transport definition => for other protocols then TCP/UDP, set iCustomProtocolNum only
- // Rule.ConditionSwitchList is not possible to set via this fnc, use a separate fnc for already existing rule
- // if strRemIpAddrID is set, then strRemIpAddr is ignored. This is valid for strIfaceIpAddr and strDayTime similarly.
- // returns strRuleID or "" on error
- //
- function FW_AddRuleImpl( strTransportID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts,
- strRemIpAddrID, strRemIpAddr, strLocIpAddrID, strLocIpAddr, eZoneMask,
- strAppGroupID, strAppLabel, iAccount, iAccessResult, iAuditLevel,
- strRuleDescription, bHighPriority, bPreferred, bDisabled, bUseClientParser,
- strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR, eOSVersion,
- bAvoidSavingSDB )
- {
- try {
- var ruleList = FW_getRuleList(bUseClientParser, false);
- var newRule = ruleList.CreateRule();
-
- // generate the RuleID => must be unique and must maintain server/client syntax
- newRule.RuleID = ruleList.GenerateRuleID( OT_FW_TRANS, parseBoolean(bUseClientParser) == 0 );
- // newRule.RuleIDString is created automatically when newRule.RuleID is set
-
- newRule.Application = strAppGroupID ? strAppGroupID : strAppLabel;
- newRule.AppType = strAppGroupID ? AT_DEFINITION : AT_LABEL;
- newRule.Priority = PRIOR_NORMAL;
-
- if ( !parseBoolean( bUseClientParser ))
- newRule.Priority = ( parseBoolean(bHighPriority) == 1) ? PRIOR_HIGH : PRIOR_LOW;
-
- newRule.Description = strRuleDescription ? strRuleDescription : "";
-
- newRule.RemIPAddrType = strRemIpAddrID ? RT_DEFINITION : RT_DIRECT;
- newRule.RemIPAddress = strRemIpAddrID ? strRemIpAddrID : (strRemIpAddr ? strRemIpAddr : "*");
-
- // if object does not exist then create it
- if ( strRemIpAddrID && isLDAPSupported() && isLDAPName(strRemIpAddrID) && !parseBoolean(bUseClientParser))
- {
- var definitionList = getDefinitionList(false);
-
- try
- {
- var definition = definitionList.Get( strRemIpAddrID );
- }
- catch (e)
- {
- definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strRemIpAddrID;
- definition.ObjectType = OT_FW_IPADDR;
-
- definitionList.Insert( definition );
- }
- }
-
- if (strLocIpAddrID || strLocIpAddr)
- {
- newRule.LocIPAddrType = strLocIpAddrID ? RT_DEFINITION : RT_DIRECT;
- newRule.LocIPAddress = strLocIpAddrID ? strLocIpAddrID : (strLocIpAddr ? strLocIpAddr : "*");
- }
-
- // if object does not exist then create it
- if ( strLocIpAddrID && isLDAPSupported() && isLDAPName(strLocIpAddrID) && !parseBoolean(bUseClientParser))
- {
- var definitionList = getDefinitionList(false);
-
- try
- {
- var definition = definitionList.Get( strLocIpAddrID );
- }
- catch (e)
- {
- definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strLocIpAddrID;
- definition.ObjectType = OT_FW_IPADDR;
-
- definitionList.Insert( definition );
- }
- }
-
- newRule.TransportType = strTransportID ? RT_DEFINITION : RT_DIRECT;
- if (strTransportID)
- newRule.TransportID = strTransportID;
- else
- FW_SetTransportObjectImpl( newRule.TransportObject, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
-
- newRule.Zone = (eZoneMask ? parseInt(eZoneMask) : 0) ? parseInt(eZoneMask) : (ZI_BIT_SAFE | ZI_BIT_DANGEROUS); // ZI_ALL_ZONES goes to exception here
-
- newRule.Account = iAccount;
-
- newRule.AccessDescriptor.AccessType = AT_NETWORK_ACCESS;
- newRule.AccessDescriptor.AuditLevel = iAuditLevel ? parseInt(iAuditLevel) : 0;
- newRule.AccessDescriptor.AccessResult = iAccessResult ? parseInt(iAccessResult) : 0;
-
- // rarely used fields
- newRule.OutConditionAND = iOutConditionAND ? parseInt(iOutConditionAND) : 0;
- newRule.OutConditionOR = iOutConditionOR ? parseInt(iOutConditionOR) : 0;
- // don't really know the TimeOfDay format....
- newRule.TimeOfDayType = strDayTimeID ? RT_DEFINITION : RT_DIRECT;
- newRule.TimeOfDay = strDayTimeID ? strDayTimeID : (strDayTime ? strDayTime : "");
- newRule.Assignment = strUsers ? strUsers : "*"; //newRule.Assignment = (window.external.Context ? Assignment : "*");
- newRule.Enabled = ( parseBoolean(bDisabled) == 1 ) ? false : true;
- newRule.Preferred = ( parseBoolean(bPreferred) == 1 ) ? true : false;
- newRule.OSVersion = eOSVersion ? parseInt(eOSVersion) : OSVER_WIN_ALL;
-
- var strRuleID = newRule.RuleIDString;
-
- ruleList.Insert(newRule, newRule);
-
- if ( !parseBoolean(bAvoidSavingSDB) )
- SaveParser(bUseClientParser);
-
- return strRuleID;
-
- } catch(e){
- ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED );
- return "";
- }
- }
-
- function FW_MoveRuleToServerDB( strSrcRuleID, bHighPriority )
- {
- try {
- var ruleList = FW_getRuleList(true, false);
- var rule = ruleList.Get(strSrcRuleID);
-
- var ruleList = FW_getRuleList(false, false);
- var newRule = ruleList.CreateRule();
-
- // generate the RuleID => must be unique and must maintain server/client syntax
- newRule.RuleID = ruleList.GenerateRuleID( OT_FW_TRANS, true );
- // newRule.RuleIDString is created automatically when newRule.RuleID is set
-
- newRule.Application = rule.Application;
- newRule.AppType = rule.AppType;
- //newRule.Priority = rule.Priority;
- newRule.Priority = ( bHighPriority ? PRIOR_HIGH : PRIOR_LOW);
- newRule.Description = rule.Description;
-
- newRule.RemIPAddrType = rule.RemIPAddrType;
- newRule.RemIPAddress = rule.RemIPAddress;
-
- newRule.LocIPAddrType = rule.LocIPAddrType;
- newRule.LocIPAddress = rule.LocIPAddress;
-
- ////////////////////////
- newRule.TransportType = rule.TransportType;
- newRule.TransportID = rule.TransportID;
-
- newRule.TransportObject.Content = ""; // assuming used only in Definitions
- newRule.TransportObject.Protocol = rule.TransportObject.Protocol;
- newRule.TransportObject.Direction = rule.TransportObject.Direction;
-
- newRule.TransportObject.CustomProtocolNumber = rule.TransportObject.CustomProtocolNumber;
- newRule.TransportObject.ICMPType = rule.TransportObject.ICMPType;
-
- newRule.TransportObject.LocalPortFrom = rule.TransportObject.LocalPortFrom;
- newRule.TransportObject.LocalPortTo = rule.TransportObject.LocalPortTo;
- newRule.TransportObject.RemotePortFrom = rule.TransportObject.RemotePortFrom;
- newRule.TransportObject.RemotePortTo = rule.TransportObject.RemotePortTo;
- ////////////////////////
-
- newRule.Zone = rule.Zone;
-
- newRule.Account = rule.Account;
-
- newRule.AccessDescriptor.AccessType = rule.AccessDescriptor.AccessType;
- newRule.AccessDescriptor.AuditLevel = rule.AccessDescriptor.AuditLevel;
- newRule.AccessDescriptor.AccessResult = rule.AccessDescriptor.AccessResult;
-
- // rarely used fields
- newRule.OutConditionAND = rule.OutConditionAND;
- newRule.OutConditionOR = rule.OutConditionOR;
-
- // don't really know the TimeOfDay format....
- newRule.TimeOfDayType = rule.TimeOfDayType;
- newRule.TimeOfDay = rule.TimeOfDay;
- newRule.Assignment = rule.Assignment;
- newRule.Enabled = rule.Enabled;
- newRule.Preferred = false;//rule.Preferred;
- newRule.OSVersion = rule.OSVersion;
-
- var strRuleID = newRule.RuleIDString;
-
- ruleList.Insert(newRule, newRule);
-
- // delete source rule
- FW_DeleteRule( strSrcRuleID, true );
-
- SaveParser(true);
- SaveParser(false);
-
- return strRuleID;
-
- } catch(e){
- ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED );
- return "";
- }
- }
-
- function FW_CopyRule( strSrcRuleID, bUseClientParser, bAvoidSavingSDB )
- {
- try {
- var ruleList = FW_getRuleList(bUseClientParser, false);
- var newRule = ruleList.CreateRule();
-
- var ruleList = FW_getRuleList(bUseClientParser, false);
- var rule = ruleList.Get(strSrcRuleID);
-
- // generate the RuleID => must be unique and must maintain server/client syntax
- newRule.RuleID = ruleList.GenerateRuleID( OT_FW_TRANS, parseBoolean(bUseClientParser) == 0 );
- // newRule.RuleIDString is created automatically when newRule.RuleID is set
-
- newRule.Application = rule.Application;
- newRule.AppType = rule.AppType;
- newRule.Priority = rule.Priority;
- newRule.Description = rule.Description;
-
- newRule.RemIPAddrType = rule.RemIPAddrType;
- newRule.RemIPAddress = rule.RemIPAddress;
-
- newRule.LocIPAddrType = rule.LocIPAddrType;
- newRule.LocIPAddress = rule.LocIPAddress;
-
- ////////////////////////
- newRule.TransportType = rule.TransportType;
- newRule.TransportID = rule.TransportID;
-
- newRule.TransportObject.Content = ""; // assuming used only in Definitions
- newRule.TransportObject.Protocol = rule.TransportObject.Protocol;
- newRule.TransportObject.Direction = rule.TransportObject.Direction;
-
- newRule.TransportObject.CustomProtocolNumber = rule.TransportObject.CustomProtocolNumber;
- newRule.TransportObject.ICMPType = rule.TransportObject.ICMPType;
-
- newRule.TransportObject.LocalPortFrom = rule.TransportObject.LocalPortFrom;
- newRule.TransportObject.LocalPortTo = rule.TransportObject.LocalPortTo;
- newRule.TransportObject.RemotePortFrom = rule.TransportObject.RemotePortFrom;
- newRule.TransportObject.RemotePortTo = rule.TransportObject.RemotePortTo;
- ////////////////////////
-
- newRule.Zone = rule.Zone;
-
- newRule.Account = rule.Account;
-
- newRule.AccessDescriptor.AccessType = rule.AccessDescriptor.AccessType;
- newRule.AccessDescriptor.AuditLevel = rule.AccessDescriptor.AuditLevel;
- newRule.AccessDescriptor.AccessResult = rule.AccessDescriptor.AccessResult;
-
- // rarely used fields
- newRule.OutConditionAND = rule.OutConditionAND;
- newRule.OutConditionOR = rule.OutConditionOR;
-
- // don't really know the TimeOfDay format....
- newRule.TimeOfDayType = rule.TimeOfDayType;
- newRule.TimeOfDay = rule.TimeOfDay;
- newRule.Assignment = rule.Assignment;
- newRule.Enabled = rule.Enabled;
- newRule.Preferred = rule.Preferred;
- newRule.OSVersion = rule.OSVersion;
-
- var strRuleID = newRule.RuleIDString;
-
- ruleList.Insert(newRule, newRule);
-
- if ( !parseBoolean(bAvoidSavingSDB) )
- SaveParser(bUseClientParser);
-
- return strRuleID;
-
- } catch(e){
- ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED );
- return "";
- }
- }
-
- function FW_CopyRoutedRule( strSrcRuleID, bAvoidSavingSDB )
- {
- try {
- var ruleList = FW_getRuleList(false, true);
-
- var newRule = ruleList.CreateRule();
- var rule = ruleList.Get(strSrcRuleID);
-
- // generate the RuleID => must be unique and must maintain server/client syntax
- newRule.RuleID = ruleList.GenerateRuleID( true );
- // newRule.RuleIDString is created automatically when newRule.RuleID is set
-
- newRule.Priority = rule.Priority;
- newRule.Description = rule.Description;
-
- newRule.RemIPAddrType = rule.RemIPAddrType;
- newRule.RemIPAddress = rule.RemIPAddress;
-
- newRule.LANIPAddrType = rule.LANIPAddrType;
- newRule.LANIPAddress = rule.LANIPAddress;
-
- newRule.IfaceIPAddrType = rule.IfaceIPAddrType;
- newRule.IfaceIPAddress = rule.IfaceIPAddress;
-
- ////////////////////////
- newRule.TransportType = rule.TransportType;
- newRule.TransportID = rule.TransportID;
-
- newRule.TransportObject.Content = ""; // assuming used only in Definitions
- newRule.TransportObject.Protocol = rule.TransportObject.Protocol;
- newRule.TransportObject.Direction = rule.TransportObject.Direction;
-
- newRule.TransportObject.CustomProtocolNumber = rule.TransportObject.CustomProtocolNumber;
- newRule.TransportObject.ICMPType = rule.TransportObject.ICMPType;
-
- newRule.TransportObject.LocalPortFrom = rule.TransportObject.LocalPortFrom;
- newRule.TransportObject.LocalPortTo = rule.TransportObject.LocalPortTo;
- newRule.TransportObject.RemotePortFrom = rule.TransportObject.RemotePortFrom;
- newRule.TransportObject.RemotePortTo = rule.TransportObject.RemotePortTo;
- ////////////////////////
-
- newRule.AccessDescriptor.AccessType = rule.AccessDescriptor.AccessType;
- newRule.AccessDescriptor.AuditLevel = rule.AccessDescriptor.AuditLevel;
- newRule.AccessDescriptor.AccessResult = rule.AccessDescriptor.AccessResult;
-
- // rarely used fields
- newRule.OutConditionAND = rule.OutConditionAND;
- newRule.OutConditionOR = rule.OutConditionOR;
-
- // don't really know the TimeOfDay format....
- newRule.TimeOfDayType = rule.TimeOfDayType;
- newRule.TimeOfDay = rule.TimeOfDay;
-
- newRule.Enabled = rule.Enabled;
- newRule.OSVersion = rule.OSVersion;
-
- var strRuleID = newRule.RuleIDString;
- ruleList.Insert(newRule, newRule);
-
- if ( !parseBoolean(bAvoidSavingSDB) )
- SaveParser();
-
- return strRuleID;
-
- } catch(e){
- ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED );
- return "";
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_EditRuleImpl
- // either strTransportID can be used or combination of eProtocol, iCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts
- // Transport definition => for PROT_ICMP, set eDirection and eICMPType only
- // Transport definition => for PROT_IP => nothing to set
- // Transport definition => for other protocols then TCP/UDP, set iCustomProtocolNum only
- // Rule.ConditionSwitchList is not possible to set via this fnc, use a separate fnc for already existing rule
- // if strRemIpAddrID is set, then strRemIpAddr is ignored. This is valid for strIfaceIpAddr and strDayTime similarly.
- // returns strRuleID or "" on error
- //
- function FW_EditRuleImpl( strRuleID, strTransportID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts,
- strRemIpAddrID, strRemIpAddr, strLocIpAddrID, strLocIpAddr, eZoneMask,
- strAppGroupID, strAppLabel, iAccount, iAccessResult, iAuditLevel,
- strRuleDescription, bHighPriority, bPreferred, bDisabled, bUseClientParser,
- strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR, eOSVersion,
- bAvoidSavingSDB )
- {
- try {
- var ruleList = FW_getRuleList(bUseClientParser, false);
- var newRule = ruleList.Get(strRuleID);
-
- newRule.Application = strAppGroupID ? strAppGroupID : strAppLabel;
- newRule.AppType = strAppGroupID ? AT_DEFINITION : AT_LABEL;
- newRule.Priority = PRIOR_NORMAL;
-
- if ( !parseBoolean( bUseClientParser ))
- newRule.Priority = ( parseBoolean(bHighPriority) == 1) ? PRIOR_HIGH : PRIOR_LOW;
-
- newRule.Description = strRuleDescription ? strRuleDescription : "";
-
- newRule.RemIPAddrType = strRemIpAddrID ? RT_DEFINITION : RT_DIRECT;
- newRule.RemIPAddress = strRemIpAddrID ? strRemIpAddrID : (strRemIpAddr ? strRemIpAddr : "*");
-
- // if object does not exist then create it
- if ( strRemIpAddrID && isLDAPSupported() && isLDAPName(strRemIpAddrID) && !parseBoolean(bUseClientParser))
- {
- var definitionList = getDefinitionList(false);
-
- try
- {
- var definition = definitionList.Get( strRemIpAddrID );
- }
- catch (e)
- {
- definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strRemIpAddrID;
- definition.ObjectType = OT_FW_IPADDR;
-
- definitionList.Insert( definition );
- }
- }
-
- newRule.LocIPAddrType = strLocIpAddrID ? RT_DEFINITION : RT_DIRECT;
- newRule.LocIPAddress = strLocIpAddrID ? strLocIpAddrID : (strLocIpAddr ? strLocIpAddr : "*");
-
- // if object does not exist then create it
- if ( strLocIpAddrID && isLDAPSupported() && isLDAPName(strLocIpAddrID) && !parseBoolean(bUseClientParser))
- {
- var definitionList = getDefinitionList(false);
-
- try
- {
- var definition = definitionList.Get( strLocIpAddrID );
- }
- catch (e)
- {
- definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strLocIpAddrID;
- definition.ObjectType = OT_FW_IPADDR;
-
- definitionList.Insert( definition );
- }
- }
-
- newRule.TransportType = strTransportID ? RT_DEFINITION : RT_DIRECT;
- if (strTransportID)
- newRule.TransportID = strTransportID;
- else
- FW_SetTransportObjectImpl( newRule.TransportObject, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
-
- newRule.Zone = (eZoneMask ? parseInt(eZoneMask) : 0) ? parseInt(eZoneMask) : (ZI_BIT_SAFE | ZI_BIT_DANGEROUS); // ZI_ALL_ZONES goes to exception here
-
- newRule.Account = iAccount;
-
- newRule.AccessDescriptor.AccessType = AT_NETWORK_ACCESS;
- newRule.AccessDescriptor.AuditLevel = iAuditLevel ? parseInt(iAuditLevel) : 0;
- newRule.AccessDescriptor.AccessResult = iAccessResult ? parseInt(iAccessResult) : 0;
-
- // rarely used fields
- newRule.OutConditionAND = iOutConditionAND ? parseInt(iOutConditionAND) : 0;
- newRule.OutConditionOR = iOutConditionOR ? parseInt(iOutConditionOR) : 0;
- // don't really know the TimeOfDay format....
- newRule.TimeOfDayType = strDayTimeID ? RT_DEFINITION : RT_DIRECT;
- newRule.TimeOfDay = strDayTimeID ? strDayTimeID : (strDayTime ? strDayTime : "");
- newRule.Assignment = strUsers ? strUsers : "*"; //newRule.Assignment = (window.external.Context ? Assignment : "*");
- newRule.Enabled = ( parseBoolean(bDisabled) == 1 ) ? false : true;
- newRule.Preferred = ( parseBoolean(bPreferred) == 1 ) ? true : false;
- newRule.OSVersion = eOSVersion ? parseInt(eOSVersion) : OSVER_WIN_ALL;
-
- if ( !parseBoolean(bAvoidSavingSDB) )
- SaveParser(bUseClientParser);
-
- return strRuleID;
-
- } catch(e){
- ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED );
- return "";
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_DeleteRule
- function FW_DeleteRule( strRuleID, bUseClientParser, bAvoidSavingSDB )
- {
- try {
- var ruleList = FW_getRuleList(bUseClientParser, false);
- var rule = ruleList.Get(strRuleID);
- if (rule)
- ruleList.Remove(rule);
-
- if (parseBoolean(bAvoidSavingSDB)==0)
- SaveParser(bUseClientParser);
-
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_DELETE_FW_RULE_FAILED, STR_DELETE_FW_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_AddRoutedRuleImpl - in addition => strInternalIpAddrID, strInternalIpAddr
- // missing - eZoneMask, strAppGroupID, strAppLabel, bIsSystemAccount, bPreferred, bUseClientParser, strUsers
- // returns strRuleID or empty if error
- function FW_AddRoutedRuleImpl( strTransportID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts,
- strRemIpAddrID, strRemIpAddr, strInternalIpAddrID, strInternalIpAddr, strIfaceIpAddrID, strIfaceIpAddr,
- iAccessResult, iAuditLevel,
- strRuleDescription, bHighPriority, bDisabled,
- strDayTimeID, strDayTime,
- iOutConditionAND, iOutConditionOR, eOSVersion,
- bAvoidSavingSDB )
- {
- try {
- var ruleList = external.ServerParser(XM_FW).RoutedRuleList;
- var newRule = ruleList.CreateRule();
-
- // generate the RuleID => must be unique and must maintain server/client syntax
- newRule.RuleID = ruleList.GenerateRuleID( true );
-
- // newRule.RuleIDString is created automatically when newRule.RuleID is set
- newRule.Priority = (parseBoolean(bHighPriority) != 0) ? PRIOR_HIGH : PRIOR_LOW;
-
- newRule.Description = strRuleDescription ? strRuleDescription : "";
-
- newRule.RemIPAddrType = strRemIpAddrID ? RT_DEFINITION : RT_DIRECT;
- newRule.RemIPAddress = strRemIpAddrID ? strRemIpAddrID : (strRemIpAddr ? strRemIpAddr : "*");
-
- // if object does not exist then create it
- if ( strRemIpAddrID && isLDAPSupported() && isLDAPName(strRemIpAddrID))
- {
- var definitionList = getDefinitionList(false);
-
- try
- {
- var definition = definitionList.Get( strRemIpAddrID );
- }
- catch (e)
- {
- definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strRemIpAddrID;
- definition.ObjectType = OT_FW_IPADDR;
-
- definitionList.Insert( definition );
- }
- }
-
- newRule.LANIPAddrType = strInternalIpAddrID ? RT_DEFINITION : RT_DIRECT;
- newRule.LANIPAddress = strInternalIpAddrID ? strInternalIpAddrID : (strInternalIpAddr ? strInternalIpAddr : "*");
-
- // if object does not exist then create it
- if ( strInternalIpAddrID && isLDAPSupported() && isLDAPName(strInternalIpAddrID))
- {
- var definitionList = getDefinitionList(false);
-
- try
- {
- var definition = definitionList.Get( strInternalIpAddrID );
- }
- catch (e)
- {
- definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strInternalIpAddrID;
- definition.ObjectType = OT_FW_IPADDR;
-
- definitionList.Insert( definition );
- }
- }
-
- if (strIfaceIpAddrID || strIfaceIpAddr)
- {
- newRule.IfaceIPAddrType = strIfaceIpAddrID ? RT_DEFINITION : RT_DIRECT;
- newRule.IfaceIPAddress = strIfaceIpAddrID ? strIfaceIpAddrID : (strIfaceIpAddr ? strIfaceIpAddr : "*");
- }
-
- newRule.TransportType = strTransportID ? RT_DEFINITION : RT_DIRECT;
- if (strTransportID)
- newRule.TransportID = strTransportID;
- else
- FW_SetTransportObjectImpl( newRule.TransportObject, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
-
- newRule.AccessDescriptor.AccessType = AT_NETWORK_ACCESS;
- newRule.AccessDescriptor.AuditLevel = iAuditLevel ? parseInt(iAuditLevel) : 0;
- newRule.AccessDescriptor.AccessResult = iAccessResult ? parseInt(iAccessResult) : 0;
-
- // rarely used fields
- newRule.OutConditionAND = iOutConditionAND ? parseInt(iOutConditionAND) : 0;
- newRule.OutConditionOR = iOutConditionOR ? parseInt(iOutConditionOR) : 0;
- // don't really know the TimeOfDay format....
- newRule.TimeOfDayType = strDayTimeID ? RT_DEFINITION : RT_DIRECT;
- newRule.TimeOfDay = strDayTimeID ? strDayTimeID : (strDayTime ? strDayTime : "");
- newRule.Enabled = ( parseBoolean(bDisabled) == 1 ) ? false : true;
- newRule.OSVersion = eOSVersion ? parseInt(eOSVersion) : OSVER_WIN_ALL;
-
- var strRuleID = newRule.RuleIDString;
-
- ruleList.Insert(newRule, newRule);
-
- if (parseBoolean(bAvoidSavingSDB)==0)
- SaveParser(false);
-
- return strRuleID;
-
- } catch(e){
- ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED );
- return "";
- }
- }
-
- function FW_EditRoutedRuleImpl( strRuleID, strTransportID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts,
- strRemIpAddrID, strRemIpAddr, strInternalIpAddrID, strInternalIpAddr, strIfaceIpAddrID, strIfaceIpAddr,
- iAccessResult, iAuditLevel,
- strRuleDescription, bHighPriority, bDisabled,
- strDayTimeID, strDayTime,
- iOutConditionAND, iOutConditionOR, eOSVersion,
- bAvoidSavingSDB )
- {
- try {
- var ruleList = FW_getRuleList(false, true);
- var newRule = ruleList.Get(strRuleID);
-
- // newRule.RuleIDString is created automatically when newRule.RuleID is set
- newRule.Priority = (parseBoolean(bHighPriority) != 0) ? PRIOR_HIGH : PRIOR_LOW;
-
- newRule.Description = strRuleDescription ? strRuleDescription : "";
-
- newRule.RemIPAddrType = strRemIpAddrID ? RT_DEFINITION : RT_DIRECT;
- newRule.RemIPAddress = strRemIpAddrID ? strRemIpAddrID : (strRemIpAddr ? strRemIpAddr : "*");
-
- // if object does not exist then create it
- if ( strRemIpAddrID && isLDAPSupported() && isLDAPName(strRemIpAddrID))
- {
- var definitionList = getDefinitionList(false);
-
- try
- {
- var definition = definitionList.Get( strRemIpAddrID );
- }
- catch (e)
- {
- definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strRemIpAddrID;
- definition.ObjectType = OT_FW_IPADDR;
-
- definitionList.Insert( definition );
- }
- }
-
- newRule.LANIPAddrType = strInternalIpAddrID ? RT_DEFINITION : RT_DIRECT;
- newRule.LANIPAddress = strInternalIpAddrID ? strInternalIpAddrID : (strInternalIpAddr ? strInternalIpAddr : "*");
-
- // if object does not exist then create it
- if ( strInternalIpAddrID && isLDAPSupported() && isLDAPName(strInternalIpAddrID))
- {
- var definitionList = getDefinitionList(false);
-
- try
- {
- var definition = definitionList.Get( strInternalIpAddrID );
- }
- catch (e)
- {
- definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strInternalIpAddrID;
- definition.ObjectType = OT_FW_IPADDR;
-
- definitionList.Insert( definition );
- }
- }
-
- newRule.IfaceIPAddrType = strIfaceIpAddrID ? RT_DEFINITION : RT_DIRECT;
- newRule.IfaceIPAddress = strIfaceIpAddrID ? strIfaceIpAddrID : (strIfaceIpAddr ? strIfaceIpAddr : "*");
-
- newRule.TransportType = strTransportID ? RT_DEFINITION : RT_DIRECT;
- if (strTransportID)
- newRule.TransportID = strTransportID;
- else
- FW_SetTransportObjectImpl( newRule.TransportObject, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
-
- newRule.AccessDescriptor.AccessType = AT_NETWORK_ACCESS;
- newRule.AccessDescriptor.AuditLevel = iAuditLevel ? parseInt(iAuditLevel) : 0;
- newRule.AccessDescriptor.AccessResult = iAccessResult ? parseInt(iAccessResult) : 0;
-
- // rarely used fields
- newRule.OutConditionAND = iOutConditionAND ? parseInt(iOutConditionAND) : 0;
- newRule.OutConditionOR = iOutConditionOR ? parseInt(iOutConditionOR) : 0;
- // don't really know the TimeOfDay format....
- newRule.TimeOfDayType = strDayTimeID ? RT_DEFINITION : RT_DIRECT;
- newRule.TimeOfDay = strDayTimeID ? strDayTimeID : (strDayTime ? strDayTime : "");
- newRule.Enabled = ( parseBoolean(bDisabled) == 1 ) ? false : true;
- newRule.OSVersion = eOSVersion ? parseInt(eOSVersion) : OSVER_WIN_ALL;
-
- if (parseBoolean(bAvoidSavingSDB)==0)
- SaveParser(false);
-
- return strRuleID;
-
- } catch(e){
- ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED );
- return "";
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_DeleteRoutedRule
- function FW_DeleteRoutedRule( strRuleID, bAvoidSavingSDB )
- {
- try {
- var ruleList = external.ServerParser(XM_FW).RoutedRuleList;
- var rule = ruleList.Get(strRuleID);
- if (rule)
- ruleList.Remove(rule);
-
- if ( !parseBoolean(bAvoidSavingSDB) )
- SaveParser( false )
-
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_DELETE_FW_RULE_FAILED, STR_DELETE_FW_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_EnableRule
- function FW_EnableRule( strRuleID, bDisabled, bUseClientParser, bIsRoutedRule, bAvoidSavingSDB )
- {
- try {
- /* alert( strRuleID )
- alert( bDisabled )
- alert( bUseClientParser )
- alert( bIsRoutedRule )*/
-
- var ruleList = FW_getRuleList(bUseClientParser, bIsRoutedRule);
- var rule = ruleList.Get(strRuleID);
-
- if (rule)
- {
- rule.Enabled = ( parseBoolean(bDisabled) == 1 ) ? false : true; //!(parseBoolean(bDisable) != 0);
- }
-
- if ( !parseBoolean(bAvoidSavingSDB) )
- SaveParser(bUseClientParser);
-
- return SUCCESS;
- } catch(e){
- return ErrorHandler( ERR_EDIT_FW_RULE_FAILED, STR_EDIT_FW_RULE_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_SetTransportObjectImpl - should not be used from html, it is used internally by scripts only
- function FW_SetTransportObjectImpl( TransportObject, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts )
- {
- var prot = TransportObject;
- prot.Content = ""; // assuming used only in Definitions
- prot.Protocol = eProtocol ? parseInt(eProtocol) : 0;
- prot.Direction = eDirection ? parseInt(eDirection) : 0;
-
- if (PROT_OTHER == prot.Protocol)
- {
- var iProt = 0;
- var iProtFrom = 0;
- var iProtTo = 0;
-
- if ( strCustomProtocolNum.toString().search("-") > -1 )
- {
- var index = strCustomProtocolNum.search("-");
-
- var strProtFrom = strCustomProtocolNum.substring(0,index);
- var strProtTo = strCustomProtocolNum.substring(index + 1);
-
- iProtFrom = parseInt(strProtFrom);
- iProtTo = parseInt(strProtTo);
- }
- else
- {
- iProtFrom = parseInt(strCustomProtocolNum);
- iProtTo = parseInt(strCustomProtocolNum);
- }
-
- iProt = (iProtTo * 65536) + iProtFrom;
-
- prot.CustomProtocolNumber = iProt; //isNaN(parseInt(iCustomProtocolNum)) ? 0 : parseInt(iCustomProtocolNum);
- }
- else if (PROT_ICMP == prot.Protocol ) {
- prot.ICMPType = isNaN(parseInt(eICMPType)) ? 0 : parseInt(eICMPType);
- } else if (PROT_TCP == prot.Protocol || PROT_UDP == prot.Protocol || PROT_TCP_UDP == prot.Protocol || PROT_TCP_S == prot.Protocol) {
-
- prot.LocalPortFrom = 0;
- prot.LocalPortTo = 0;
- prot.RemotePortFrom = 0;
- prot.RemotePortTo = 0;
-
- if (strLocalPorts)
- {
- if ( strLocalPorts == "*")
- prot.LocalPortTo = 65535;
- else
- {
- prot.LocalPortFrom = parseInt(strLocalPorts);
- var Idx = strLocalPorts.search( "-" );
- if ((-1) != Idx)
- prot.LocalPortTo = parseInt( strLocalPorts.substr(Idx+1) );
- else
- prot.LocalPortTo = prot.LocalPortFrom;
- }
- }
- if (strRemotePorts)
- {
- if ( strRemotePorts == "*")
- prot.RemotePortTo = 65535;
- else
- {
- prot.RemotePortFrom = parseInt(strRemotePorts);
- var Idx = strRemotePorts.search( "-" );
- if ((-1) != Idx)
- prot.RemotePortTo = parseInt( strRemotePorts.substr(Idx+1) );
- else
- prot.RemotePortTo = prot.RemotePortFrom;
- }
- }
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_AddPredefinedProtocolAndPortsObject
- function FW_AddPredefinedProtocolAndPortsObject( strProtAndPortsObjectID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts, bUseClientParser )
- {
- try {
- var definitionList = getDefinitionList(bUseClientParser);
- var definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strProtAndPortsObjectID;
- definition.ObjectType = OT_FW_TRANS;
-
- var newItem = definition.ItemList.CreateItem();
- FW_SetTransportObjectImpl( newItem, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
- definition.ItemList.Insert(newItem);
-
- definitionList.Insert( definition );
-
- SaveParser(bUseClientParser);
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_ADDING_FW_OBJECT_FAILED, STR_ADDING_FW_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_EditPredefinedProtocolAndPortsObject
- function FW_EditPredefinedProtocolAndPortsObject( strProtAndPortsObjectID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts, bUseClientParser )
- {
- try {
- var definitionList = getDefinitionList(bUseClientParser);
- var definition = definitionList.Get( strProtAndPortsObjectID );
-
- var itemEnum = new Enumerator(definition.ItemList);
- itemEnum.moveFirst();
- var item = itemEnum.item();
-
- FW_SetTransportObjectImpl( item, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
- SaveParser(bUseClientParser);
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_EDIT_FW_OBJECT_FAILED, STR_EDIT_FW_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_DeletePredefinedProtocolAndPortsObject - removes it from FW
- function FW_DeletePredefinedProtocolAndPortsObject( strProtAndPortsObjectID, bUseClientParser )
- {
- // remove it from FW database
- try {
- var definitionList = getDefinitionList(bUseClientParser);
- var definition = definitionList.Get( strProtAndPortsObjectID );
-
- if (definition)
- definitionList.Remove(definition);
-
- SaveParser(bUseClientParser);
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_DELETE_FW_OBJECT_FAILED, STR_DELETE_FW_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_AddPredefinedIPAddressObject
- function FW_AddPredefinedIPAddressObject( strIPAddressObjectID, strIPAddress, bUseClientParser )
- {
- try {
- var definitionList = getDefinitionList(bUseClientParser);
- var definition = definitionList.CreateDefinition();
-
- definition.DefinitionID = strIPAddressObjectID;
- definition.ObjectType = OT_FW_IPADDR;
-
-
- if (strIPAddress)
- {
-
- var newItem = definition.ItemList.CreateItem();
- newItem.Content = strIPAddress;
- definition.ItemList.Insert(newItem);
- }
-
- definitionList.Insert( definition );
-
- SaveParser(bUseClientParser);
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_ADDING_FW_OBJECT_FAILED, STR_ADDING_FW_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_DeletePredefinedIPAddressObject
- function FW_DeletePredefinedIPAddressObject( strIPAddressObjectID, bUseClientParser )
- {
- // remove it from FW database
- try {
- var definitionList = getDefinitionList(bUseClientParser);
- var definition = definitionList.Get( strIPAddressObjectID );
-
- if (definition)
- definitionList.Remove(definition);
-
- SaveParser(bUseClientParser);
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_DELETE_FW_OBJECT_FAILED, STR_DELETE_FW_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_AddIPAddressToPredefinedObject
- function FW_AddIPAddressToPredefinedObject( strIPAddressObjectID, strIPAddress, bUseClientParser )
- {
- try {
- var definitionList = getDefinitionList(bUseClientParser);
- var definition = definitionList.Get( strIPAddressObjectID );
-
- var newItem = definition.ItemList.CreateItem();
- newItem.Content = strIPAddress;
- definition.ItemList.Insert(newItem);
-
- SaveParser(bUseClientParser);
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_EDIT_FW_OBJECT_FAILED, STR_EDIT_FW_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_ClearAllIPAddressesFromPredefinedObject
- function FW_ClearAllIPAddressesFromPredefinedObject( strIPAddressObjectID, bUseClientParser )
- {
- try {
- var definitionList = getDefinitionList(bUseClientParser);
- var definition = definitionList.Get( strIPAddressObjectID );
-
- definition.ItemList.Clear();
-
- SaveParser(bUseClientParser);
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_EDIT_FW_OBJECT_FAILED, STR_EDIT_FW_OBJECT_FAILED );
- }
- }
-
-
- ///////////////////////////////////////////////////////////////////////
- // FW_RemoveIPAddressFromPredefinedObject
- function FW_RemoveIPAddressFromPredefinedObject( strIPAddressObjectID, strIPAddress, bUseClientParser )
- {
- try {
- var definitionList = getDefinitionList(bUseClientParser);
- var definition = definitionList.Get( strIPAddressObjectID );
-
- var itemEnum = new Enumerator(definition.ItemList);
- itemEnum.moveFirst();
-
- while (!itemEnum.atEnd())
- {
- var item = itemEnum.item();
- if (item.Content == strIPAddress)
- {
- definition.ItemList.Remove(item);
- break;
- }
- itemEnum.moveNext();
- }
-
- SaveParser(bUseClientParser);
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_EDIT_FW_OBJECT_FAILED, STR_EDIT_FW_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_AddRuleTriggerCondition
- function FW_AddRuleTriggerCondition( strRuleID, eCondType, eCondTarget, iBitsOn, iBitsOff, bUseClientParser )
- {
- try {
- var ruleList = external.ServerParser(XM_FW).RoutedRuleList;
- var rule = ruleList.Get( strRuleID );
-
- var newConditionSwitch = rule.ConditionSwitchList.CreateConditionSwitch();
- newConditionSwitch.Type = eCondType;
- newConditionSwitch.Target = eCondTarget;
- newConditionSwitch.BitsOn = iBitsOn;
- newConditionSwitch.BitsOff = iBitsOff;
-
- rule.ConditionSwitchList.Insert(newConditionSwitch);
-
- SaveParser( false )
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_ADDING_FW_OBJECT_FAILED, STR_ADDING_FW_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_ClearAllRuleTriggerConditions
- function FW_ClearAllRuleTriggerConditions( strRuleID, bUseClientParser )
- {
- try {
- var ruleList = external.ServerParser(XM_FW).RoutedRuleList;
- var rule = ruleList.Get( strRuleID );
-
- rule.ConditionSwitchList.Clear();
-
- SaveParser( false );
-
- return SUCCESS;
- }
- catch(e) {
- return ErrorHandler( ERR_DELETE_FW_OBJECT_FAILED, STR_DELETE_FW_OBJECT_FAILED );
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_GetPropertyValue
- function FW_GetPropertyValue( strPropertyID )
- {
- try {
- var propList = external.ServerParser(XM_FW).GlobalOptions;
- var prop = propList.Get( strPropertyID );
-
- return prop.Value;
- } catch(e) {
- return "";
- }
- }
-
- ///////////////////////////////////////////////////////////////////////
- // FW_SetPropertyValue
- function FW_SetPropertyValue( strPropertyID, Value, eType )
- {
- var propList = null;
- try {
- propList = external.ServerParser(XM_FW).GlobalOptions;
- } catch(e) {
- return ErrorHandler( ERR_EDIT_FW_PROPERTY_FAILED, STR_EDIT_FW_PROPERTY_FAILED );
- }
-
- var prop = null;
- try {
- prop = propList.Get( strPropertyID );
- } catch(e) {
- }
-
- try {
- if (!prop)
- {
- prop = propList.CreateProperty();
- prop.Type = eType;
- prop.PropertyID = strPropertyID;
- propList.Insert(prop);
- }
- switch ( parseInt(eType) )
- {
- case PT_INT:
- prop.Value = parseInt(Value);
- break;
- case PT_BOOL:
- prop.Value = parseBoolean(Value);
- break;
- default:
- prop.Value = Value;
-
- }
- //external.Save();
- SaveParser( false )
-
- return SUCCESS;
- } catch(e) {
- return ErrorHandler( ERR_EDIT_FW_PROPERTY_FAILED, STR_EDIT_FW_PROPERTY_FAILED );
- }
- }
-